home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-05-25 | 1.3 KB | 60 lines | [TEXT/CWIE] |
- #include "Solution.h"
-
- #include "ProblemUtils.h"
-
- #include <stdio.h>
- #include <string.h>
- #include <Files.h>
- #include <Errors.h>
-
- pascal OSErr CheckTextProcess( const FSSpec* infile, const FSSpec* outfile )
- {
- OSErr err;
- Handle data = NULL;
- UInt32 action_count = 0;
- ActionRecord action;
- ActionRecord **actions = NULL;
- char line[MAX_LINE_LEN];
- char *p;
-
- actions = (ActionRecord **) NewHandle( 0 );
- err = MemError();
- if ( err == noErr ) {
- err = ProblemFileRead( infile, &data );
- }
- if ( err == noErr ) {
- while ( ProblemReadLineFromHandle( data, line, MAX_LINE_LEN ) ) {
- if ( strcmp( line, "END" ) == 0 ) {
- break;
- }
- p = line;
- if ( ProblemGetUInt32( &p, &action.action )
- && ProblemGetSInt32( &p, &action.amount )
- && ProblemGetUInt32( &p, &action.flags ) ) {
- ProblemGetString( &p, action.search );
- ProblemGetString( &p, action.replace );
- err = PtrAndHand( &action, (Handle) actions, sizeof(ActionRecord));
- action_count++;
- ProblemLogError( err, "CheckTextProcess: PtrAndHand" );
- } else {
- ProblemLogError( -1, "CheckTextProcess: not numbers" );
- }
- }
- HLock( (Handle) actions );
- TextProcess( data, action_count, *actions );
- err = ProblemFileWrite( outfile, data );
- DisposeHandle( data );
- }
- return err;
- }
-
- int main()
- {
- printf( "Starting\n" );
-
- ProblemRunFileTests( CheckTextProcess );
-
- return 0;
- }
-
-